package com.org.manhu.chargehelper.tools;

import java.util.Map;

import com.org.manhu.chargehelper.constant.Constant;

import android.content.Context;
import android.content.SharedPreferences;

/**
 *
 * @文件名：SharedPreferncesClass.java
 * @包名：com.org.manhu.custom
 * @作者：李朋辉 @ QQ：892839211
 * @创建时间：2014年12月5日 下午4:05:23
 * 
 * @描述：配置文件
 */
public class SharedPreferncesUtil {

	/**
	 * @描述：用来存储信息
	 * @param context
	 *            上下文环境
	 * @param key
	 *            用户要存储的信息的键值
	 * @param value
	 *            用户要存储的信息
	 */
	public static void saveInfo(Context context, String key, String value) {
		SharedPreferences sp = context.getSharedPreferences("helper_setting",
				Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = sp.edit();
		editor.putString(key, value);
		editor.commit();
	}

	/**
	 * @描述：获取sharepreferences中的信息
	 * @param context
	 *            上下文环境
	 * @param key
	 *            用户要获取的信息的键值
	 * @return
	 */
	public static String getInfo(Context context, String key) {
		SharedPreferences sp = context.getSharedPreferences("helper_setting",
				Context.MODE_PRIVATE);
		return sp.getString(key, "");
	}

	public static void saveMoney(Context context, float value) {
		SharedPreferences sp = context.getSharedPreferences("helper_setting",
				Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = sp.edit();
		editor.putFloat(Constant.SP_USER_MONEY, value);
		editor.commit();
	}

	public static float getMoney(Context context) {
		SharedPreferences sp = context.getSharedPreferences("helper_setting",
				Context.MODE_PRIVATE);
		return sp.getFloat(Constant.SP_USER_MONEY, (float) 0.00);
	}

	public static void saveNickName(Context context, String value) {
		SharedPreferences sp = context.getSharedPreferences("helper_setting",
				Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = sp.edit();
		editor.putString(Constant.SP_NICK_NAME, value);
		editor.commit();
	}

	public static String getNickName(Context context) {
		SharedPreferences sp = context.getSharedPreferences("helper_setting",
				Context.MODE_PRIVATE);
		return sp
				.getString(Constant.SP_NICK_NAME, "mh_" + DeviceInfo.getIMEI());
	}

	public static void saveBoxInfo(Context context, Map<String, String> info) {
		SharedPreferences sp = context.getSharedPreferences("helper_setting",
				Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = sp.edit();
		editor.putString(Constant.SP_BOX_CHANNELID,
				info.get(Constant.SP_BOX_CHANNELID));
		editor.putString(Constant.SP_BOX_DEVID, info.get(Constant.SP_BOX_DEVID));
		editor.commit();
	}

	public static String getBoxInfo(Context context, String key) {
		SharedPreferences sp = context.getSharedPreferences("helper_setting",
				Context.MODE_PRIVATE);
		return sp.getString(key, "0");
	}

}
